// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function formIncident() {
    document.forms["form_id"].submit();
//    setTimeout("location.reload(true);",timeoutPeriod);
}

function lancer_fichier(fichier) {

    if(window.XMLHttpRequest) // FIREFOX
        xhr_object = new XMLHttpRequest();
    else if(window.ActiveXObject) // IE
        xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
    else
        return(false);
    xhr_object.open("GET", fichier, false);

    xhr_object.send(null);
    if(xhr_object.readyState == 4 && xhr_object.status == 200) {
        //alert(xhr_object.responseText) ;
        //alert ("1");
        return(xhr_object.responseText);
    }
    else return(false);
}

function menuLink(id,link){
    var dest = document.getElementById(id);
    dest.innerHTML = lancer_fichier(link);

}

function menuLink1(id){
    var dest = document.getElementById(id);
    //dest.innerHTML = lancer_fichier(link);
    document.form1.submit();
}

function interrogation(){
    var dest = document.getElementById('content') ;
    //dest.innerHTML = lancer_fichier("/interomachine");
    document.location = "/machines/interomachine";
// document.form1.submit();
}

function submitLink(f){
    document.forms[f].submit();
}

        sections = ['group0','group1','group2','group3','group4','group5','group6','group7','group8','group9'];
	function createNewSection(name) {
		var name = $F('sectionName');
		if (name != '') {
			var newDiv = Builder.node('div', {id: 'group' + (sections.length + 1), overlap:'horizontal' ,className: 'section', style: 'display:none;'}, [
				Builder.node('h3', {className: 'handle'}, name)
			]);

			sections.push(newDiv.id);
			$('page').appendChild(newDiv);
			Effect.Appear(newDiv.id);
			destroyLineItemSortables();
			createLineItemSortables();
			createGroupSortable();
		}
                
	}

	function createLineItemSortables() {
		for(var i = 0; i < sections.length; i++) {
			Sortable.create(sections[i],{tag:'div',dropOnEmpty: true, overlap:'horizontal', containment: sections,only:'lineitem'});
		
                getIdMachine(i);
                
            }

	}

	function destroyLineItemSortables() {
		for(var i = 0; i < sections.length; i++) {
			Sortable.destroy(sections[i]);
                        
		}
                 window.alert("destry");
	}

	function createGroupSortable() {
		Sortable.create('page',{tag:'div',only:'section',handle:'handle'});
                window.alert("ok");
	}

	/*
	Debug Functions for checking the group and item order
	*/
	function getGroupOrder() {
		var sections = document.getElementsByClassName('section');
		var alerttext = '';
		sections.each(function(section) {
			var sectionID = section.id;
			var order = Sortable.serialize(sectionID);
			alerttext += sectionID + ': ' + Sortable.sequence(section) + '\n';
		});
		alert(alerttext);
		return false;
            }
         function getIdMachine(id){
             document.write(document.getElementById(id));
         }
    

function showMachine(id){
    var listeMachines = document.getElementById("listeMachines");
	listeMachines.innerHTML = lancer_fichier("/machines?salleid="+id);

  }
 function scanMachine(){
    var resultScan = document.getElementById('resultScan');
    var machine_memoire = document.getElementById('machine_memoire').value;
    var machine_cpu = document.getElementById('machine_cpu').value;

    var machine_espacedisque = document.getElementById('p_machine_espacedisque').value;
    var machine_ping = document.getElementById('machine_ping').value;
    alert(machine_espacedisque);
    resultScan.innerHTML = lancer_fichier('/machines/scanmachine?memoire='+machine_memoire+'&cpu='+machine_cpu+'&disc='+machine_espacedisque+'&ping='+machine_ping);

  }

  function hideShow(id){
      var el = document.getElementById(id);
      var display = el.style.display ? '' : 'none';
      el.style.display = display;
  }

/**
 * Drag and drop
 */
